#encoding=utf8
'''
Created on 2012-10-18

@author: Administrator
'''
from dispatch.Processor import Processor
from pub import Func, UserDict, RoomDict;
from pub.Config import Config

class RIKOClass(Processor):
    '''
    指令：RIKO(room idiom kick out) 
    备注：房主踢走玩家
    格式：c-s:cmd#cmdId#roomId#masterId#outId
     s-c:cmd#cmdId#roomId# masterId # masterNickName # outId#outUsernickName
    
    '''
    def __init__(self,):
        Processor.__init__(self,)
        self.__roomId = 0;
        self.__userId = 0;
        self.__userOutId = 0;
        
    def dataValidtor(self, cmdContent):
        if not cmdContent:
            return False;
        paraLen = len(cmdContent);
        if paraLen == 3:      
            self.__roomId = Func.strToInt(cmdContent[0], Config.I_SYS_ZERO);
            self.__userId = Func.strToInt(cmdContent[1], Config.I_SYS_ZERO);
            self.__userOutId = Func.strToInt(cmdContent[2], Config.I_SYS_ZERO);                 
            return True;        
        return False;
    def outData(self,):
        room = RoomDict.getRoomFromDictById(self.__roomId);
        if not room:
            return False;
        userOut = UserDict.getUserFromUserDictById(self.__userOutId);
        if not userOut:
            return False;
        outNickName = userOut.get_user_nick_name();
        owner = room.get_room_owner();
        if not owner:
            return False;
        ownerNickName = owner.get_user_nick_name();
        
        if owner.get_user_id() != self.__userId:
            return False;
        RoomDict.delUserToRoom(userOut, self.__roomId);#删除
        sendData = [self.__roomId, self.__userId, ownerNickName, self.__userOutId, outNickName];
        sendStr = self.setPackage(sendData);
        RoomDict.sendInfoToRoomAllUser(roomObj=room, cmd="", msg=sendStr, isPackage=False);
        return True;
        
        
        
            
